package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RoomInfoMapper;
import com.ruoyi.system.domain.RoomInfo;
import com.ruoyi.system.service.IRoomInfoService;

/**
 * 房间信息Service业务层处理
 */
@Service
public class RoomInfoServiceImpl implements IRoomInfoService {
    @Autowired
    private RoomInfoMapper roomInfoMapper;

    /**
     * 查询房间信息
     * 
     * @param id 房间ID
     * @return 房间信息
     */
    @Override
    public RoomInfo selectRoomInfoById(Long id) {
        return roomInfoMapper.selectRoomInfoById(id);
    }

    /**
     * 查询房间信息列表
     * 
     * @param roomInfo 房间信息
     * @return 房间信息
     */
    @Override
    public List<RoomInfo> selectRoomInfoList(RoomInfo roomInfo) {
        return roomInfoMapper.selectRoomInfoList(roomInfo);
    }

    /**
     * 新增房间信息
     * 
     * @param roomInfo 房间信息
     * @return 结果
     */
    @Override
    public int insertRoomInfo(RoomInfo roomInfo) {
        // 生成房间编码
        String maxCode = roomInfoMapper.getMaxRoomCode();
        String newCode;
        if (maxCode == null) {
            newCode = "RM0001";
        } else {
            int num = Integer.parseInt(maxCode.substring(2)) + 1;
            newCode = String.format("RM%04d", num);
        }
        roomInfo.setRoomCode(newCode);
        return roomInfoMapper.insertRoomInfo(roomInfo);
    }

    /**
     * 修改房间信息
     * 
     * @param roomInfo 房间信息
     * @return 结果
     */
    @Override
    public int updateRoomInfo(RoomInfo roomInfo) {
        return roomInfoMapper.updateRoomInfo(roomInfo);
    }

    /**
     * 批量删除房间信息
     * 
     * @param ids 需要删除的房间ID
     * @return 结果
     */
    @Override
    public int deleteRoomInfoByIds(Long[] ids) {
        return roomInfoMapper.deleteRoomInfoByIds(ids);
    }

    /**
     * 删除房间信息信息
     * 
     * @param id 房间ID
     * @return 结果
     */
    @Override
    public int deleteRoomInfoById(Long id) {
        return roomInfoMapper.deleteRoomInfoById(id);
    }
} 